//
//  UserLocalInfo.m
//  MyChatDemo
//
//  Created by DragonYao on 2017/9/11.
//  Copyright © 2017年 DragonYao. All rights reserved.
//

#import "UserLocalInfo.h"

@interface UserLocalInfo ()


@end

@implementation UserLocalInfo

+ (UserLocalInfo *)sharedUserInfo {
    static UserLocalInfo *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[[self class] alloc] init];
    });
    return instance;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        self.userDfs = [NSUserDefaults standardUserDefaults];
        self.userId = [self.userDfs stringForKey:kUserNumberId];
        self.userPwd = [self.userDfs stringForKey:kUserPassword];
        self.userRegisterId = [self.userDfs stringForKey:kUserRegisterId];
        self.userRegisterPwd = [self.userDfs stringForKey:kRegisterPassword];
        self.hasLogin = [self.userDfs boolForKey:kUserHasLogin];
        [self.userDfs synchronize];
    }
    return self;
}

- (void)setUserId:(NSString *)userId {
    if (_userId == userId) return;
    _userId = userId;
    [self.userDfs setValue:_userId forKey:kUserNumberId];
    [self.userDfs synchronize];
}

- (void)setUserPwd:(NSString *)userPwd {
    if (_userPwd == userPwd) return;
    _userPwd = userPwd;
    [self.userDfs setValue:_userPwd forKey:kUserPassword];
    [self.userDfs synchronize];
}

- (void)setUserRegisterId:(NSString *)userRegisterId {
    if (_userRegisterId == userRegisterId) return;
    _userRegisterId = userRegisterId;
    [self.userDfs setObject:_userRegisterId forKey:kUserRegisterId];
    [self.userDfs synchronize];
}

- (void)setUserRegisterPwd:(NSString *)userRegisterPwd {
    if (_userRegisterPwd == userRegisterPwd) return;
    _userRegisterPwd= userRegisterPwd;
    [self.userDfs setObject:_userRegisterPwd forKey:kRegisterPassword];
    [self.userDfs synchronize];
}

- (void)setHasLogin:(BOOL)hasLogin {
    if (_hasLogin == hasLogin) return;
    _hasLogin = hasLogin;
    [self.userDfs setBool:_hasLogin forKey:kUserHasLogin];
    [self.userDfs synchronize];
}

- (NSString *)myJid {
    return [NSString stringWithFormat:@"%@@%@", self.userId, kLoginDomain];
}

@end
